﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace SHomeWorkshop.LunarSF.StudentInfosManager.Converters
{
    /// <summary>
    /// 在户口性质名称与对应的索引值之间进行转换。
    /// </summary>
    [ValueConversion(typeof(string), typeof(int))]
    public class ResidenceTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            switch (value.ToString())
            {
                case "未落常住户口": return 0;
                case "非农业家庭户口": return 1;
                case "农业家庭户口": return 2;
                case "非农业集体户口": return 3;
                case "农业集体户口": return 4;
            }

            return -1;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int)
            {
                switch ((int)value)
                {
                    case 0: return "未落常住户口";
                    case 1: return "非农业家庭户口";
                    case 2: return "农业家庭户口";
                    case 3: return "非农业集体户口";
                    case 4: return "农业集体户口";
                }
            }

            return "";
        }

        private static ResidenceTypeConverter converter = new ResidenceTypeConverter();

        public static ResidenceTypeConverter Instance
        {
            get { return converter; }
        }
    }
}
